package com.stylefeng.guns.modular.model.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.CarFile;
import com.stylefeng.guns.modular.model.service.ICarFileService;

/**
 * model控制器
 *
 * @author fengshuonan
 * @Date 2018-08-01 19:21:10
 */
@Controller
@RequestMapping("/carFile")
public class CarFileController extends BaseController {

    private String PREFIX = "/model/carFile/";

    @Autowired
    private ICarFileService carFileService;

    /**
     * 跳转到model首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "carFile.html";
    }

    /**
     * 跳转到添加model
     */
    @RequestMapping("/carFile_add")
    public String carFileAdd() {
        return PREFIX + "carFile_add.html";
    }

    /**
     * 跳转到修改model
     */
    @RequestMapping("/carFile_update/{carFileId}")
    public String carFileUpdate(@PathVariable Integer carFileId, Model model) {
        CarFile carFile = carFileService.selectById(carFileId);
        model.addAttribute("item",carFile);
        LogObjectHolder.me().set(carFile);
        return PREFIX + "carFile_edit.html";
    }

    /**
     * 获取model列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return carFileService.selectList(null);
    }

    /**
     * 新增model
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(CarFile carFile) {
        carFileService.insert(carFile);
        return SUCCESS_TIP;
    }

    /**
     * 删除model
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer carFileId) {
        carFileService.deleteById(carFileId);
        return SUCCESS_TIP;
    }

    /**
     * 修改model
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(CarFile carFile) {
        carFileService.updateById(carFile);
        return SUCCESS_TIP;
    }

    /**
     * model详情
     */
    @RequestMapping(value = "/detail/{carFileId}")
    @ResponseBody
    public Object detail(@PathVariable("carFileId") Integer carFileId) {
        return carFileService.selectById(carFileId);
    }
}
